// pages/order_check/order_check.ts
export { };
const urls = require("../../utils/urls");
const navigate = require("../../utils/navigate");


class Place {
    "uuid": string;
    // 地图 选点
    "longitude": string;
    "latitude": string;
    "province": string;
    "city": string;
    // 县 和 区
    "region": string;
    // 街道
    "street": string;
    // 检测地点 名称
    "place_name": string;
    "admin_uuid": string;
};

Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 城市
        "city": "",
        // 县 和 区
        "region": "",
        // 街道
        "street": "",
        // 检测地点 名称
        "place_name": "",
        "check_places": ([] as Place[])
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        this.get_location_and_check_place();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    get_location_and_check_place() {
        // 由于 还未审核 无法调用 定位 接口 
        // fake 定位信息
        this.setData({
            "city": "北京市",
            "region": "东城区",
            "street": "东华门街道",
            "place_name": "xxx小区",
        });
        // 请求 核酸检测 地点
        this.get_check_places();
    },
    get_check_places() {
        let that = this;
        const city = that.data.city;
        const region = that.data.region;
        const street = that.data.street;

        wx.request({
            url: urls.gc_get_places_url,
            data: {
                "city": city,
                "region": region,
                "street": street,
            },
            success(res: any) {
                console.log("request gc_get_places_url");
                console.log(res);
                let check_places = res.data.places;
                for (let [i, v] of check_places.entries()) {
                    v["index"] = i;
                }
                that.setData({
                    check_places: check_places,
                })
            }
        });
    },
    go_to_order_check_task(e: any) {
        const place_index = e.currentTarget.dataset.place_index;
        const place = this.data.check_places[place_index];
        if (place.uuid == null) {
            wx.showToast({
                title: 'uuid获取失败',
                icon: 'error',
                duration: 2000,
                mask: true
            })
        } else {
            wx.setStorageSync("select_order_check_place", place);
            navigate.to_order_check_task();
        }
    }
})